package com.forum.common.event;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

/**
 * 消息事件发布服务
 * 用于在各个服务中发布消息事件
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class MessageEventPublisher {
    
    private final RabbitTemplate rabbitTemplate;
    
    /**
     * 消息交换机
     */
    private static final String MESSAGE_EXCHANGE = "message-exchange";
    
    /**
     * 路由键
     */
    private static final String AUDIT_ROUTING_KEY = "message.audit";
    private static final String LIKE_ROUTING_KEY = "message.like";
    private static final String COMMENT_ROUTING_KEY = "message.comment";
    private static final String MENTION_ROUTING_KEY = "message.mention";
    
    /**
     * 发布帖子审核事件
     * 
     * @param event 帖子审核事件
     */
    public void publishPostAuditEvent(PostAuditEvent event) {
        log.info("发布帖子审核事件: {}", event);
        rabbitTemplate.convertAndSend(MESSAGE_EXCHANGE, AUDIT_ROUTING_KEY, event);
    }
    
    /**
     * 发布点赞事件
     * 
     * @param event 点赞事件
     */
    public void publishLikeEvent(LikeEvent event) {
        log.info("发布点赞事件: {}", event);
        rabbitTemplate.convertAndSend(MESSAGE_EXCHANGE, LIKE_ROUTING_KEY, event);
    }
    
    /**
     * 发布评论事件
     * 
     * @param event 评论事件
     */
    public void publishCommentEvent(CommentEvent event) {
        log.info("发布评论事件: {}", event);
        rabbitTemplate.convertAndSend(MESSAGE_EXCHANGE, COMMENT_ROUTING_KEY, event);
    }
    
    /**
     * 发布提及事件
     * 
     * @param event 提及事件
     */
    public void publishMentionEvent(MentionEvent event) {
        log.info("发布提及事件: {}", event);
        rabbitTemplate.convertAndSend(MESSAGE_EXCHANGE, MENTION_ROUTING_KEY, event);
    }
} 